﻿using Entitas;
using System.Linq;
class EnemyRoamingMovementRequestSystem : IExecuteSystem
{
    EnemyContext enemyContext;
    RequestContext requestContext;
    public EnemyRoamingMovementRequestSystem(Contexts contexts)
    {
        enemyContext = contexts.enemy;
        requestContext = contexts.request;
    }
    public void Execute()
    {
        foreach (var e in enemyContext.GetEntities().Where(x => x.isRoaming == true && x.hasRoamingTimer && x.roamingTimer.value > 0
        && x.hasDirection))
        {

            switch (e.direction.value)
            {
                case Direction.Up:
                    requestContext.CreateEntity().AddRoamingMovementRequest(e.name.value, Direction.Up);
                    break;
                case Direction.Up_Left:
                    requestContext.CreateEntity().AddRoamingMovementRequest(e.name.value, Direction.Up_Left);
                    break;
                case Direction.Up_Right:
                    requestContext.CreateEntity().AddRoamingMovementRequest(e.name.value, Direction.Up_Right);
                    break;
                case Direction.Down:
                    requestContext.CreateEntity().AddRoamingMovementRequest(e.name.value, Direction.Down);
                    break;
                case Direction.Down_Left:
                    requestContext.CreateEntity().AddRoamingMovementRequest(e.name.value, Direction.Down_Left);
                    break;
                case Direction.Down_Right:
                    requestContext.CreateEntity().AddRoamingMovementRequest(e.name.value, Direction.Down_Right);
                    break;
                case Direction.Left:
                    requestContext.CreateEntity().AddRoamingMovementRequest(e.name.value, Direction.Left);
                    break;
                case Direction.Right:
                    requestContext.CreateEntity().AddRoamingMovementRequest(e.name.value, Direction.Right);
                    break;
                default:
                    break;
            }

        }

    }
}
